<script>
export default {
  onLaunch: function () {
    console.log('App Launch')
    uni.request({
      url: 'https://aaf2ad37-cad8-4edf-8138-6903fe1b5608.bspapp.com/http/YibanAPP',
      method: 'GET',
      dataType: 'json',
      success: res => {
        var wgtVersion = '2.0.0'
        var isUpload = false
        if (res.data.version != wgtVersion) {
          isUpload = true;
        }
        if (isUpload == true) {
          // 下载文件资源到本地，下载刚才打包的 .wgt文件
          console.log('开始下载文件' + res.data.url)
          uni.downloadFile({
            url: 'https://cbdtwoh5.tx1.isart.me/__UNI__C45B3DF.wgt', // 下载资源的 url
            success: (downloadResult) => {
              if (downloadResult.statusCode === 200) {
                plus.runtime.install(downloadResult.tempFilePath, {
                  force: true
                }, function() {
                  // 应用热重启，重新启动进入首页。
                  plus.runtime.restart();
                  isUpload = false;
                  console.log('安装成功', 'install success...');
                }, function(e) {
                  console.error('安装失败', 'install fail...');
                });
              }
            }
          });
        }
      }
    });
    uni.getSystemInfo({
      success: (res) => {
        uni.setStorageSync('system_info', res);
      }
    });
    uni.onTabBarMidButtonTap(() => {
      this.$uniNavigateTo({
        url: '/pages/publish/publish',
        animationType: 'slide-in-bottom'
      })
    })
    const jyJPush = uni.requireNativePlugin("JY-JPush");
    jyJPush.addJYJPushReceiveOpenNotificationListener(result=> {
      console.log('接到通知')
      console.log(result)
//  监听成功后，若点击推送消息，会触发result；数据格式保持极光返回的安卓/iOS数据一致
      plus.runtime.setBadgeNumber(0);
      this.$uniNavigateTo({
        url: '/pages/news/news',
        query:{
          type: result.type,
          tab_cur: result.tab_cur,
        }
      })
    });
    jyJPush.addJYJPushReceiveNotificationListener(result=> {
      console.log('收到推送')
      console.log(result)
//  监听成功后，若收到推送，会在result返回对应的数据；数据格式保持极光返回的安卓/iOS数据一致
      this.$emit('handleGetRedDot')
    });
  },
  onShow: function () {
    setTimeout(() => {
      // #ifdef APP-PLUS
      plus.navigator.closeSplashscreen()
      // #endif
    }, 2000)
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
}
</script>

<style>
@import "uni.scss";
@import "colorui/main.css";
@import "style/main.scss";
@import "colorui/icon.css";
/*每个页面公共css */
</style>
